<?php

namespace App\Http\Controllers\App;

use App\Helpers\HttpClass;
use App\Helpers\Price;
use App\Helpers\utils\Chart;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class PriceController extends Controller
{
    public function history(Request $request)
    {
        $query = $request->get('query');
        preg_match_all("#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#",
            $query,
            $results
        );
        if (count($results) == 0 || count($results[0]) == 0) {
            return rsp(40010);
        }
        $p = new Price();
        $url = $results[0][0];
        return $p->getPrice($url);
    }
}
